home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-11-06 | 4.0 KB | 179 lines | [TEXT/MSET] |
- (*
-
- BaseControl is used for subclassing all controls ( pushButton, checkBox+,
- vscrollbar, and hscrollbar) and is similar to the standard Mops control
- but with some notable exceptions. First, we allow any control to be
- positioned (but not drawn) and have its value(s) set before it is actually
- made new:. Also, we make controls into selectionn objects so that they
- will follow our standard selection protocol. See the actual control
- subclasses for examples of use.
-
-
- *)
-
- variable THECTL \ storage needed by FindControl in method click:
-
- \ **** CLICK SUPPORT
- \ note that click: is very general and will support scrollbars
-
- 0 value MPOINT
-
- \ using thisCtl can often be the best way to add special actions to controls
- 0 value thisCtl
-
- : CTLEXEC \ ( part# ctlHndl -- ) Executes action for control.
- 0 swap call GetCRefCon dup -> thisCtl exec: ** ;
-
- \ CtlProc is the procedure to be executed when a control is being tracked.
-
- :proc CTLPROC \ ( ctlHndl int:part -- )
- word0 swap ctlExec ;proc
-
-
- \ baseControl is the root class for all controls
-
- :class baseControl super{ nullSelect }
-
- int PROCID
- int RESID
- handle CTLHNDL
- int theVALUE
- rect+ bounds
- ptr wind \ the owning window
-
- \ ****** THE FOLLOWING METHODS ARE SAFE TO USE WHEN NOT ALIVE
-
- :m alive?: ( -- b )
- nil?: CTLHNDL not ;m
-
- :m RELEASE:
- alive?: self
- IF
- get: ctlHndl call DisposControl
- clear: ctlHndl
- THEN ;m
-
- :m GETRECT: \ ( -- l t r b ) Stacks bounds rectangle
- get: bounds \ we always maintain bounds, even when alive
- ;m
-
- :m PUTRESID: \ ( resID -- )
- put: resID ;m
-
- :m MOVETO: { x y -- } \ Moves control to x,y location
- alive?: self
- IF
- get: ctlhndl x y pack call MoveControl
- THEN
- x y moveto: bounds ;m
-
- :m MOVE: { dx dy -- }
- alive?: self
- IF
- dx dy ptr: ctlhndl 8 + move: rect+ \ message to class
- THEN
- dx dy move: bounds \ must always maintain bounds
- ;m
-
- :m SETSIZE: { w h -- } \ Sets width, height of control's rect
- alive?: self
- IF
- get: ctlhndl w h pack call SizeControl
- THEN
- w h setsize: bounds ;m
-
- :m SIZE: \ ( -- w h )
- alive?: self
- IF
- ptr: ctlhndl 8 + size: rect \ message to class
- ELSE
- size: bounds
- THEN
- ;m
-
- :m SETRECT: { l t r b -- }
- l t moveto: self
- r l - b t - setsize: self ;m
-
- :m PUT: { theVal -- } \ Sets the ctl value.
- alive?: self
- IF get: ctlHndl theVal makeint call SetCtlValue
- ELSE theVal put: theVALUE
- THEN
- ;m
-
- \ if alive, get must always look in the toolbox record because even though
- \ we could try to maintain theVALUE ourselves the toolbox can change the
- \ control's value via TrackControl
- :m GET: \ ( -- theVal )
- alive?: self
- IF
- word0 get: ctlHndl call GetCtlValue word0
- ELSE
- get: theValue
- THEN
- ;m
-
-
-
- :m draw: \ Cause the control to be drawn
- alive?: self 0exit
- get: CtlHndl call Draw1Control ;m
-
- :m HIDE:
- alive?: self 0exit
- get: Ctlhndl call HideControl ;m
-
- :m SHOW:
- alive?: self 0exit
- get: Ctlhndl call ShowControl ;m
-
- :m HILITE: \ ( hiliteState -- ) Hilite a part or entire control
- alive?: self 0exit
- get: ctlHndl swap makeInt
- call HiliteControl ;m
-
- :m deactivate:
- alive?: self 0exit \ 27Feb94 DBH
- -1 hilite: self ;m
-
- :m activate:
- alive?: self 0exit \ 27Feb94 DBH
- 0 hilite: self ;m
-
- :m hit?: ( -- b )
- where: theMouse
- addr: bounds Ptinrect ;m
-
-
- :m click: { \ part ^ctl action1 action2 -- }
- where: fEvent g->l -> mpoint \ save mouse loc
- word0 mpoint get: wind theCtl call FindControl
- word0 -> part
- theCtl @ -> ^ctl \ control handle, should be same as get: ctlHndl
-
- part
- CASE[ konst inThumb ], [ konst inCheckBox ], [ konst inButton ]=>
- 0 -> action1 \ no action while tracking
- ['] ctlExec -> action2 \ just exec: after mouse up
- DEFAULT=>
- \ but if in scroll up/dn or pageup/pagedn then exec: repeatedly
- drop
- ['] ctlproc -> action1
- ['] 2drop -> action2 \ do nothing after mouse up
- ]CASE
-
- ^ctl
- IF word0 ^ctl mpoint action1 call TrackControl word0 ( part#)
- ^ctl action2 execute
- THEN ;m
-
-
- ;class
-
- endload
-
- *** EXAMPLE USE
-
- See control subclasses, pushButton, checkBox+, vscrollbar, and hscrollbar.
-